<?
global $DB;
//Modül ayarları yükleniyor...
include_once "settings.inc.php";
if(isset($_POST['process']))
{
	switch ($_POST['process']) 
	{
		case 'changeStatus':
			$sql = "SELECT publish_on_homepage FROM ". _MODULE_NAME ." WHERE id=" . $_POST['id'];
			$rows = $DB->fetchArray($sql);
			if(is_array($rows[0]))
			{
				if($rows[0]['publish_on_homepage'] == 1)	//-> Durumu aktif ise pasif yap
				{
					if($DB->query("UPDATE ". _MODULE_NAME ." SET publish_on_homepage=0 WHERE id=" . $_POST['id']))
						echo 'passive';
					else
						echo 'ERROR';
				}
				elseif($rows[0]['publish_on_homepage'] == 0)	//-> Durumu pasif ise aktif yap
				{
					if($DB->query("UPDATE ". _MODULE_NAME ." SET publish_on_homepage=1 WHERE id=" . $_POST['id']))
						echo 'active';
					else
						echo 'ERROR';
				}
			}
			else
				echo 'ERROR';
		break;

		case "deletePicture":
			$sql = "SELECT picture FROM ". _MODULE_NAME ." WHERE id=" . $_POST['id'];
			$rows = $DB->fetchArray($sql);
			if(is_array($rows[0]))
			{	
				if($DB->query("UPDATE " . _MODULE_NAME . " SET picture ='' WHERE id=" . $_POST['id']))
				{
					if(file_exists("../pictures/" . _MODULE_NAME . "/thumbs/" . $rows[0]['picture']) or file_exists("../pictures/" . _MODULE_NAME . "/bigs/" . $rows[0]['picture']))
					{
						@unlink("../pictures/" . _MODULE_NAME . "/thumbs/" . $rows[0]['picture']);
						@unlink("../pictures/" . _MODULE_NAME . "/bigs/" . $rows[0]['picture']);
					}
					echo 'OK';
				}
				else
					echo 'ERROR';
			}
			else
				echo 'ERROR1';
		break;
		
		case "changeRow":
			if(isset($_POST['id']) and isset($_POST['newRow']))
			{
				$id = intVal($_POST['id']);
				$newRow = intVal($_POST['newRow']);
				if($id != "" and $newRow != "")
				{
					$sql = "UPDATE " . _MODULE_NAME . " SET row=" . $newRow . " WHERE id=" . $id;
					if($DB->query($sql))
					{
						echo 'OK';
						exit;
					}
					else
					{
						echo 'ERROR'; 
						exit;
					}
				}
				else
				{
					echo 'NONE';
					exit;
				}
			}
		break;
		
		default:
			echo 'ERROR';
		break;
	}
}
else
	echo 'ERROR';
?>